<?php
/**
 * Created by PhpStorm.
 * User: ruwang
 * Date: 11/22/14
 * Time: 12:40 AM
 */

class TemplateBuilder {
    private $stringLiteralTemplate = 'template';
    private $stringLiteralView = 'view';
    private $className;
    private $methodName;
    private $defaultTemplate = 'CrypPwMainTemplate';
    private $defaultView = 'CrypPwMainView';

    public function __construct($view = false){
        if($view) {
            list($this->className, $this->methodName) = explode('::', $view);
        }
    }

    private $viewList = array('CrypPwIndex' => array(
        'index' => array('view' => 'CrypPwMainView'),
        'run' => array('view' => 'CrypPwMainView')
      )
    );

    public function getView(){
        return isset($this->viewList[$this->className][$this->methodName][$this->stringLiteralView]) ?
          $this->viewList[$this->className][$this->methodName][$this->stringLiteralView]:
          $this->defaultView;
    }

    public function getTemplate() {
        if(isset($this->viewList[$this->className][$this->methodName]) &&
          array_key_exists( $this->stringLiteralTemplate , $this->viewList[$this->className][$this->methodName])) {
            return $this->viewList[$this->className][$this->methodName][$this->stringLiteralTemplate];
        } else if(isset($this->viewList[$this->className][$this->methodName]) &&
          array_key_exists($this->stringLiteralTemplate ,$this->viewList[$this->className])){
            return $this->viewList[$this->className][$this->stringLiteralTemplate];
        } else {
            return $this->defaultTemplate;
        }
    }
} 